<template>
    <el-date-picker
      v-model="dataList"
      type="datetimerange"
      align="right"
      unlink-panels
      range-separator="至"
      start-placeholder="开始日期"
      end-placeholder="结束日期"
      :picker-options="pickerOptions"
      value-format="timestamp"
      @change="dataPickerChange"
      :default-time="defaultTime"
      size="mini"
    ></el-date-picker>
</template>
<script>
export default {
  name: "datePicker",
  model: {
    event: "change"
  },
  props: {
    value: [String, Array],
    isAll:[String,Boolean],
    defaultTime:{
      default:()=>{
        return ['00:00:00','23:59:59']
      },
      type:Array
      }
  },
  watch: {
    value(val, oldVal) {
      this.dateValue = val;
    }
  },
  data() {
    return {
      dataList: [],
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近半年",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90 * 2);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "最近一年",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90 * 4);
              picker.$emit("pick", [start, end]);
            }
          },
          {
            text: "全部",
            onClick(picker) {
              const end = "";
              const start = "";
              picker.$emit("pick", [start, end]);
            }
          }
        ]
      }
    };
  },
  methods: {
    dataPickerChange(v) {
      if(v){
        this.$emit('selectChange',v)
      }else{
        this.$emit('selectChange',["",""])
      }
    },
    reset() {
      this.dateValue = this.value;
      this.dateChange();
    },

    },

  mounted(){
     
  }
};
</script>



